package com.lhf.controller;

import com.github.pagehelper.PageInfo;
import com.lhf.entity.Person;
import com.lhf.service.PersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Controller
public class PersonController {
    @Autowired
    private PersonService service;
    @RequestMapping("/index")
    public ModelAndView getPerson(){
        ModelAndView mv= new ModelAndView("index");
        return mv;
    }
    @RequestMapping("/main")
    @ResponseBody
    public Object found(@RequestParam(required = false,defaultValue = "")String name, @RequestParam(required = false,defaultValue = "-1")String sex, @RequestParam(required = false,defaultValue = "1")Integer pageindex){
        PageInfo<Person> persons = service.getPerson(name, sex, pageindex);
        return persons;
    }
    @RequestMapping("/getxx")
    public void getxx(int id, HttpServletResponse response) throws IOException {
        response.setCharacterEncoding("utf-8");
        String getxx = service.getxx(id);
        response.getWriter().write(getxx);
    }
    public PersonService getService() {
        return service;
    }

    public void setService(PersonService service) {
        this.service = service;
    }
}
